package com.tanhua.server.controller;

import com.tanhua.domain.vo.RecommendUserQueryParam;
import com.tanhua.server.service.IMService;
import com.tanhua.server.service.TodayBestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TodayBestController {

    @Autowired
    private TodayBestService todayBestService;

    @Autowired
    private IMService imService;


    /**
     * 今日佳人：
     *  GET  /todayBest
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        return todayBestService.queryTodayBest();
    }

    /**
     * 推荐好友列表
     *  Get  /recommendation ? page=1&size=2
     *  请求参数：
     *      Query：Map集合中
     *  方法：
     *      1、int page，int size
     *      2、Page对象（page，size）
     */
    @GetMapping("/recommendation")
    public ResponseEntity queryRecommendUserList(RecommendUserQueryParam param) {
        return todayBestService.queryRecommendUserList(param);
    }

    /**
     * 佳人信息（查看用户详情）
     *  GET /:id/personalInfo
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId) {
        return todayBestService.personalInfo(userId);
    }

    /**
     * 查看陌生人问题
     *  GET /strangerQuestions
     *  参数：Query ：userId
     */
    @GetMapping("/strangerQuestions")
    public  ResponseEntity queryQuestions(Long userId) {
        return todayBestService.queryQuestions(userId);
    }

    /**
     * 回复陌生人消息
     *    POST   /strangerQuestions
     * 参数：
     *  Body：
     *     userId
     *     reply
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions(@RequestBody Map map) {
        Integer temp = (Integer) map.get("userId");
        long userId = temp.longValue();
        String reply = (String) map.get("reply");
        return imService.replyQuestions(userId,reply);
    }

    /**
     * 搜索附近的人
     *  GET /search
     *  参数：
     *      gender
     *      distance
     */
    @GetMapping("/search")
    public ResponseEntity search(
            @RequestParam(required=false) String gender,
            @RequestParam(defaultValue = "2000") String distance) {
        return todayBestService.searchNear(gender,distance);
    }
}
